package gentle.controller;


import com.baomidou.mybatisplus.plugins.Page;
import gentle.base.BaseController;
import gentle.entity.CustomerInfo;
import gentle.entity.SearchCustomerInfo;
import gentle.exception.BizExceptionEnum;
import gentle.exception.BussinessException;
import gentle.factory.PageFactory;
import gentle.service.IOrthodonticsService;
import gentle.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;


/**
 *种植俱乐部列表
 */
@Controller
@RequestMapping("/orthodonticsDetail")
public class OrthodonticsController extends BaseController {
    @Autowired
    IOrthodonticsService service;

    /**
     * 俱乐部明细管理列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object list(SearchCustomerInfo info, HttpServletRequest request) {
        if (info.getAbbreviation() == null || info.getAbbreviation() == "" || info.getAbbreviation() == "null") {
            return null;
        } else {
            Page<CustomerInfo> page = new PageFactory<CustomerInfo>().defaultPage();
            try {
                info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
                info.setLimitIndex(page.getSize());
                page.setCurrent(0);
                List<CustomerInfo> list = service.selectPageListByQueryGetMap(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = service.selectPageListByQueryGetMap(page, info);
                }
                page.setTotal(service.getQueryPagesCount(page, info));
                page.setRecords(list);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return super.packForBT(page);
        }
    }


    @RequestMapping("/sumorthodonticsDetail")
    @ResponseBody
    public HashMap sumorthodonticsDetail(@RequestParam(required = false) String reach, @RequestParam(required = false) String customerStatus,@RequestParam(required = false) String outpatientName,
                                         @RequestParam(required = false) String fieldTc, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime) {

        return service.sumorthodonticsDetail(reach, customerStatus, outpatientName,fieldTc, startTime,  endTime);
    }


    @RequestMapping(value = "/orthodonticsDetailExport")
    public void orthodonticsDetailExport(@Valid SearchCustomerInfo searchInfo, HttpServletResponse response) {
        service.orthodonticsDetailExport(searchInfo,response);
    }

    //俱乐部绑定医生
    @RequestMapping(value = "/updateDoctorOrthodontics", method = RequestMethod.POST)
    @ResponseBody
    public int updateDoctorOrthodontics(String id, String doctor, String remarks) throws Exception {
        return service.updateDoctorOrthodontics(id, doctor, remarks);
    }

}